home *** CD-ROM | disk | FTP | other *** search
- Path: anvil.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: line intersection in C
- Date: 28 Feb 1996 11:46:01 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4h2bdpINNe7h@anvil.ugrad.cs.ubc.ca>
- References: <1996Feb25.230142.29689@dcs.warwick.ac.uk> <3134933A.AB9@computek.net>
- NNTP-Posting-Host: anvil.ugrad.cs.ubc.ca
-
- In article <3134933A.AB9@computek.net>,
- robert jacobs and jason jacobs <robertj@computek.net> wrote:
- >Daniel Castillo Molero wrote:
- >>
- >> Hello,
- >>
- >> I wonder if anybody can help me to find an algorithm in C to detect whether
- >> two line segments intersect properly (I don't know if this is the correct
- >> terminology, but by proper intersection I mean that the intersection is
- >> not in the extreme of any of them and that one does not lie on top of
- >> the other).
- >> I need to test intersection just for line segments whose slope is a multiple
- >> of 45 degrees, which I suppose may simplify the solution.
- >>
- >> I would greatly appreciate any sort of help.
- >>
- >> Daniel Castillo.
- >>
- >> danmol@dcs.warwick.ac.uk
- >>
- >> --
- >> * Daniel Castillo. D.C.Molero@dcs.warwick.ac.uk *
- >
- >Plug the end points of line segements into the equation for a line.
- >Calculate the slope of the lines. If the slopes are defferent the lines
- >will intersect.
-
- This is a poor approach. No such representation exists for vertical lines,
- which have an undefined slope.
-
- An implicit equation representation is much better, because it can represent
- any lines:
-
- Ax + By = C
-
- This can represent vertical lines (just set B = 0), horizontal lines (set A =
- 0) and everything in between using finite constants for A and B.
-
-
- Furthermore, (A, B) forms a vector that is perpendicular to the line, and when
- you rotate this vector by 90 degrees, you get one that is parallel to the
- line: the rule is, swap the coordinates and negate one of them: (-B, A)
-
- If you find the parallel vector of one line and the perpendicular vector of
- another line, and take their dot product, it is zero if the two vectors are
- perpendicular which is if and only if the two lines intersect somewhere.
- --
-
-